package com.dpiinc.TechPage.pen.dialog;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import com.dpiinc.TechPage.R;

import org.jetbrains.annotations.Nullable;

/**
 * Created by hu489_000 on 2018-07-23.
 */

public class ServiceHintDialog extends BaseFloatDialog {

    private static ServiceHintDialog ServiceHintDialog;

    private Context mContext;

    private ServiceHintDialog(@Nullable Context context) {
        super(context);
    }

    public static void ShowDialog2(final Context context, final String title, final String msg) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if(showHintDialog){
                    ServiceHintDialog = new ServiceHintDialog(context);
                    ServiceHintDialog.setCanceledOnTouchOutside(true);
                    ServiceHintDialog.setCancelable(true);
                    ServiceHintDialog.show();
                    TextView tv_title = ServiceHintDialog.findViewById(R.id.tv_title);
                    tv_title.setText(title);
                    TextView tv_msg = ServiceHintDialog.findViewById(R.id.tv_msg);
                    tv_msg.setText(msg);
                }
            }
        },200);
    }

    private static boolean showHintDialog;
    public static void setShowHint(boolean showHint) {
        showHintDialog = showHint;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_service_agreement_hint);

    }

    private static Handler mHandler = new Handler();

    public static void ShowDialog(@Nullable final Context context, final String title, final String msg) {
        ServiceHintDialog = new ServiceHintDialog(context);
        ServiceHintDialog.setCanceledOnTouchOutside(true);
        ServiceHintDialog.setCancelable(true);
        ServiceHintDialog.show();
        TextView tv_title = ServiceHintDialog.findViewById(R.id.tv_title);
        tv_title.setText(title);
        TextView tv_msg = ServiceHintDialog.findViewById(R.id.tv_msg);
        tv_msg.setText(msg);
    }

    public static void dismissDialog() {
        if (ServiceHintDialog != null && ServiceHintDialog.isShowing()) {
            ServiceHintDialog.dismiss();
        }
    }

}
